
import unittest

import requests

from api.api_approve_trust import ApiApproveTrust
from api.api_register_login import ApiRegisterLogin
from api.api_tender import ApiTender
from utils import parser_html

class TenderList(unittest.TestCase):
    def setUp(self) -> None:
        self.session=requests.session()
        self.login=ApiRegisterLogin(self.session)
        self.trust=ApiApproveTrust(self.session)
        self.tender=ApiTender(self.session)
    def tearDown(self) -> None:
        self.session.close()
    def test01_tender_list(self,r="123",phone="13600003370",imgVerifyCode="8888",phonecode="666666",pwd="test123",amount=100):
        self.login.api_img_code(r)
        self.login.api_phone_code(phone=phone,imgVerifyCode=imgVerifyCode)
        self.login.api_register(phone=phone,password=pwd,verifycode=imgVerifyCode,phone_code=phonecode)
        self.login.api_login(keywords=phone,password=pwd)
        self.trust.api_approve()
        resp=self.trust.api_trust()
        # 解析html
        data = parser_html(resp)
        print("解析后的结果为：", data)
        # 请求三方开户
        result = self.session.post(url=data[0], data=data[1])
        print("三方开户结果为：", result.text)
        self.trust.api_img_code(r)
        resp=self.trust.api_recharge(valicode=imgVerifyCode)
        # 解析html
        data = parser_html(resp)
        print("解析后的结果为：", data)
        # 请求三方充值
        result = self.session.post(url=data[0], data=data[1])
        print("三方开户结果为：", result.text)
        resp=self.tender.api_tender(amount=amount)
        # 解析html
        data = parser_html(resp)
        print("解析后的结果为：", data)
        # 请求三方投资
        result = self.session.post(url=data[0], data=data[1])
        print("三方开户结果为：", result.text)